{
  "name": "Banking Personal Loan Eligibility Pre-Qualification Automation Bot",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "id": "1d40b72d-d85d-4caa-b9d9-d8419427fdff",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        2048,
        96
      ],
      "webhookId": "4eacadf9-cf98-4d3c-a1af-7a5d12def29c",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "maxEmiPercentage",
              "value": 40,
              "type": "number"
            },
            {
              "id": "id-2",
              "name": "loanMultiplier",
              "value": 0.8,
              "type": "number"
            },
            {
              "id": "id-3",
              "name": "minCreditScore",
              "value": 650,
              "type": "number"
            },
            {
              "id": "id-4",
              "name": "disclaimerText",
              "value": "This is a preliminary eligibility estimate. Final approval, interest rate, and tenure are subject to credit checks and bank policies.",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "d0aa448e-6896-4b69-b72a-7156c846b442",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        2272,
        96
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "gpt-4o-mini"
        },
        "responsesApiEnabled": false,
        "options": {
          "temperature": 0.2
        }
      },
      "id": "d2a1c83d-9d47-4e0d-8169-bc542e1c12a1",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        2160,
        336
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2928,
        96
      ],
      "id": "c00f5e56-93f0-48de-b645-5896f09b43bc",
      "name": "Send a text message",
      "webhookId": "15e52fe8-2137-454f-85e3-8d7b66bf1dfd",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Fetches available loan products with eligibility criteria including employment type, minimum income, tenure, and interest rates. Use this to match customers with suitable loan products.",
        "documentId": {
          "__rl": true,
          "value": "1LpSu1JLlunNY-uHXC074pWuMqH95pCj8zWCO10KUBNw",
          "mode": "list",
          "cachedResultName": "Loan_Products",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LpSu1JLlunNY-uHXC074pWuMqH95pCj8zWCO10KUBNw/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1LpSu1JLlunNY-uHXC074pWuMqH95pCj8zWCO10KUBNw/edit#gid=0"
        },
        "options": {}
      },
      "id": "763545c3-3644-42be-87b4-d0932e3aa3ce",
      "name": "Loan_Products_Sheet_Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        2576,
        352
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "=This tool MUST be called to store a qualified loan lead.\n\nExpected input fields:\n- customer_name (string)\n- city (string)\n- employment_type (string)\n- monthly_income (number)\n- existing_emis (string)\n- estimated_eligibility (string)\n- product_recommended (string)\n- lead_status (string)\n\n\n",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1HR-AulgLJUPfXLS1UzMryFICnixGjaC9u9Ttw8NvzvQ",
          "mode": "list",
          "cachedResultName": "Loan_Leads",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1HR-AulgLJUPfXLS1UzMryFICnixGjaC9u9Ttw8NvzvQ/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1HR-AulgLJUPfXLS1UzMryFICnixGjaC9u9Ttw8NvzvQ/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Customer_Name": "={{ $fromAI('customer_name') }}",
            "City": "={{ $fromAI('city') }}",
            "Employment_Type": "={{ $fromAI('employment_type') }}",
            "Monthly_Income": "={{ $fromAI('monthly_income') }}",
            "Existing_EMIs": "={{ $fromAI('existing_emis') }}",
            "Estimated_Eligibility": "={{ $fromAI('estimated_eligibility') }}",
            "Product_Recommended": "={{ $fromAI('product_recommended') }}",
            "Lead_Status": "Qualified"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Customer_Name",
              "displayName": "Customer_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "City",
              "displayName": "City",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employment_Type",
              "displayName": "Employment_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Monthly_Income",
              "displayName": "Monthly_Income",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Existing_EMIs",
              "displayName": "Existing_EMIs",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Estimated_Eligibility",
              "displayName": "Estimated_Eligibility",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Product_Recommended",
              "displayName": "Product_Recommended",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Lead_Status",
              "displayName": "Lead_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "455409fd-9abc-4165-b2a0-e86e9b434f7a",
      "name": "Loan_Leads_Sheet_Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        2736,
        320
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "=You are a Banking Personal Loan Pre-Eligibility Assistant for a regulated financial institution.\n\nThis is a CUSTOMER-FACING SYSTEM.\nInternal actions MUST NEVER be exposed to the customer.\n\nABSOLUTE OUTPUT CONSTRAINT\n\nWhen calling tools, you MUST provide these fields exactly:\n\n#For Loan_Leads_Sheet_Tool:\n{\n  \"customer_name\": \"string\",\n  \"customer_email\": \"string\",\n  \"city\": \"string\",\n  \"employment_type\": \"string\",\n  \"monthly_income\": \"number\",\n  \"existing_emis\": \"number\",\n  \"estimated_eligibility\": \"number\",\n  \"product_recommended\": \"string\",\n}\n\n#For Gmail_Tool:\n{\n  \"email_body\": \"string\",\n  \"customer_message\": \"string\"\n}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nMANDATORY EXECUTION SEQUENCE\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nYou MUST execute the following steps IN ORDER.\nYou are NOT allowed to skip any step.\n\nSTEP 1 — INTENT & DATA COLLECTION\nCollect all missing information conversationally:\n- Full Name\n- Email ID (if available)\n- Monthly net take-home income\n- Employment type (Salaried / Self-employed)\n- City\n- Existing EMIs (numeric, 0 if none)\n- Desired loan tenure (months)\n\nDO NOT proceed until all required fields are available.\n\nSTEP 2 — ELIGIBILITY CALCULATION (NON-NEGOTIABLE)\nYou MUST use Calculator_Tool to compute:\nEligible EMI = (Monthly Income × 0.40) − Existing EMIs\nEstimated Loan = Eligible EMI × Tenure × 0.8\n\nYou are STRICTLY FORBIDDEN from calculating mentally.\n\nSTEP 3 — PRODUCT SELECTION (MANDATORY)\nYou MUST use Loan_Products_Sheet_Tool to identify\neligible products based on:\n- Employment type\n- Minimum income criteria\n\nDO NOT recommend any product without calling this tool.\n\nSTEP 4 — LEAD CREATION (CRITICAL / NON-OPTIONAL)\nIF Estimated Loan > 0:\nYou MUST IMMEDIATELY call Loan_Leads_Sheet_Tool.\n\nWhen calling this tool, you MUST provide the following fields:\n- customer_name (Full Name)\n- city (CITY)\n- employment_type (Employment type)\n- monthly_income (Monthly net take-home income)\n- existing_emis (Existing EMIs)\n- estimated_eligibility (Estimated loan eligibility)\n- product_recommended (eligible products)\n- lead_status = \"Qualified\"\n\nSTEP 5 — EMAIL DISPATCH (MANDATORY step)\nIF an email address is available:\n\nYou MUST IMMEDIATELY call Gmail_Tool and send 2 input fields - Email ID, pre-eligibility summary.\n\nThis action MUST be executed SILENTLY.\nYou MUST NOT mention or describe this action to the customer.\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nFINAL CUSTOMER MESSAGE\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nAfter ALL above steps are completed,\nsend ONE final message to the customer that includes:\n\n- Estimated loan eligibility (rounded, INR)\n- Recommended product name\n\nIn case Loan Eligibility > 0,\n- Clear next steps (bank team will contact)\n- Mandatory disclaimer\nMANDATORY DISCLAIMER (DO NOT ALTER MEANING):\n\"This is a preliminary eligibility estimate. Final approval, interest rate, and tenure are subject to credit checks and bank policies.\"\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nCOMPLIANCE & BEHAVIOR RULES\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n- Do NOT promise loan approval\n- Do NOT expose calculations\n- Do NOT expose internal systems\n- Do NOT narrate actions\n- Maintain a professional banking tone\n"
        }
      },
      "id": "57b9c18e-d1ef-4fa6-b19f-c2a4bbaa9716",
      "name": "Personal Loan Eligibility Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        2560,
        96
      ]
    },
    {
      "parameters": {},
      "id": "85ed2d40-65a5-4e5a-b673-76b65fbdf898",
      "name": "Calculator_Tool",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "typeVersion": 1,
      "position": [
        2448,
        320
      ]
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "=Send a pre-eligibility email to the customer.\n\nExpected input fields:\n- customer_email (string, required)\n- email_body (string, required)\n\nThis tool MUST be called if customer_email is available.\n",
        "sendTo": "={{ $fromAI('customer_email') }}",
        "subject": "Your Personal Loan Pre-Eligibility Estimate",
        "message": "={{ $fromAI('email_body') }}",
        "options": {}
      },
      "id": "373f09ee-d126-4d82-a833-e332145e2cd0",
      "name": "Gmail_Tool",
      "type": "n8n-nodes-base.gmailTool",
      "typeVersion": 2.1,
      "position": [
        2896,
        384
      ],
      "webhookId": "48a30f35-3422-4c0e-aefa-d37b49940244",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $('Workflow Configuration').item.json.message.chat.id }}"
      },
      "id": "dd0fdefd-cd4e-4c4b-81a9-197d62e23850",
      "name": "Simple_Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        2304,
        352
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Loan_Products_Sheet_Tool": {
      "ai_tool": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Loan_Leads_Sheet_Tool": {
      "ai_tool": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Personal Loan Eligibility Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculator_Tool": {
      "ai_tool": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Gmail_Tool": {
      "ai_tool": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Simple_Memory": {
      "ai_memory": [
        [
          {
            "node": "Personal Loan Eligibility Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "f877ab89-e963-4635-9ffc-3f32506c6c4c",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "mmBRt2DTWoQSj3iO",
  "tags": []
}